package com.ripta;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;

import java.util.ArrayList;



public class AndroidHelloWorld extends Activity {
	/** Called when the activity is first created. */
	
	// define the add button and field
	private ImageButton addButton = null;
	private EditText addField = null;
	private TaskAdapter adapter = null;
	private ListView list = null;
	private ArrayList<TaskContent> items = null;
	
	   @Override
	   public void onCreate(Bundle savedInstanceState) {
	       super.onCreate(savedInstanceState);
	       /*
	       String languageToLoad  = "de";
	       Locale locale = new Locale(languageToLoad);
	       Locale.setDefault(locale);
	       Configuration config = new Configuration();
	       config.locale = locale;
	       getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
	       */
	       //items = (TextView) this.findViewById(R.id.TextView);
	       
	       items = new ArrayList<TaskContent>();
	       adapter = new TaskAdapter(this, R.layout.dataview, items);

	       setContentView(R.layout.main);
	       
	       list = (ListView) this.findViewById(R.id.ListView);
	       list.setAdapter(adapter);
	       
	       addButton = (ImageButton) this.findViewById(R.id.AddButton);
	       addButton.setOnClickListener(new AddHandler());
	       
	       addField = (EditText) this.findViewById(R.id.AddField);

	   }
	   
	   private class AddHandler implements View.OnClickListener
		{
			public void onClick(View v)
			{
				String newItem = addField.getText().toString();
				TaskContent data = new TaskContent();
				data.setTask(newItem);
				items.add(data);
				adapter.notifyDataSetChanged();
				addField.setText("");
			}
		}

}